/*
 * RenderDevice.cpp
 *
 *  Created on: 2009/01/25
 *      Author: Yongshik Cho
 */

#include "RenderDevice.h"
#include "Exception.h"
#include "SceneManager.h"

template<> RenderDevice* ISingleton<RenderDevice>::m_pInstance = 0;

RenderDevice::RenderDevice(Rect2D rect, DeviceSettings* sets)
{
	mViewport = Viewport(rect);
	mSettings = sets;
	mQuadtree = 0;
	mBitsPerPixel = 32;
	mBitsDepth = 0;
	mBitsStencil = 0;
	mAlphaBuffer = 1;
	mBufferCount = 2;
}

RenderDevice::~RenderDevice()
{
	SAFE_DELETE(mQuadtree);
}

void RenderDevice::setViewport(const Viewport& vp)
{
	if(mViewport == vp)
		return;

	mViewport = vp;
}

void RenderDevice::buildQuadtree(const Rect2D& rect)
{
	SAFE_DELETE(mQuadtree);

	mQuadtree = new Quadtree(0, rect);
	if(!mQuadtree)
		AltoThrow(Exception::ERR_MEMORY);

	SceneManager* sm = SceneManager::GetInstancePtr();
	assert(sm);

	sm->getRenderRoot()->buildQuadtree();
}
